﻿using AutoMapper;
using MediatR;
using ProcurementManagement.Applcation.Command.VendorCommand;
using ProcurementManagement.Applcation.Command.VendorTypeCommand;
using ProcurementManagement.Domain.Dtos;
using ProcurementManagement.Domain.ProcurementDomain;
using ProcurementManagement.Infrstructre.Interface;

namespace ProcurementManagement.Applcation.CommandHanlers.VendorCommandHanlers
{
    public class VendorTypeShowPidCommandHandlers : IRequestHandler<VendorTypeShowPidCommand, List<VendorTypePidDto>>
    {
        protected readonly InterfaceVendorTypeRepository repository;
        protected readonly IMapper mapper;

        public VendorTypeShowPidCommandHandlers(InterfaceVendorTypeRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<List<VendorTypePidDto>> Handle(VendorTypeShowPidCommand request, CancellationToken cancellationToken)
        {
            var list = (await repository.GetAll()).Where(x => x.VTFatherId==request.Id).ToList();
            return mapper.Map<List<VendorTypePidDto>>(list);

        }
    }
}
